package com.muyu.common.core.utils.im;

import cn.hutool.http.Header;
import cn.hutool.http.HttpGlobalConfig;
import cn.hutool.http.HttpRequest;
import com.alibaba.fastjson.JSONObject;
import com.muyu.common.core.constant.ImConstants;
import com.muyu.common.core.domain.Result;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class ImUtils {
    private static Logger logger = LoggerFactory.getLogger(ImUtils.class);


    /**
     * GoEasy即时通讯服务端发送消息
     */
    public static Result sendImMessage(JSONObject jsonObject) {
        String result = HttpRequest.post(ImConstants.REST_HOST + ImConstants.ADDRESS_PREFIX).header(Header.CONTENT_TYPE, "application/json").body(jsonObject.toString())
                .timeout(HttpGlobalConfig.getTimeout()).execute().body();
        JSONObject jsonResult = JSONObject.parseObject(result);
        if (jsonResult.get("code").equals(200)) {
            return Result.success("消息发送成功！");
        } else {
            return Result.error("消息发送失败{}" + jsonResult.get("msg"));
        }
    }
}
